<?php
App::uses('AppController', 'Controller');
/**
 * Records Controller
 *
 * @property Record $Record
 */
class RecordsController extends AppController {

	public $SideBarItems = array();
	public $SideBarMessage = '';
	public $HMenu = '';
	public $VMenu = '';
	
	public $SessionUserData = '';
	
	public function beforeFilter() {
		AppController::beforeFilter();
	
	
		$this->set('SideBarMessage', $this->SideBarMessage);
		$this->set('HMenu', $this->HMenu);
		
		$this->SessionUserData = $this->Session->read('SessionUserData');
	
	}
	
	
	public function index() {
		// читаем id
		$id = $this->SessionUserData;
		// устанавливаем активный пункт меню в верхем меню	
		$this->set('HMenu', 'Record');		
		// получаем список всех возможных записей
		$this->loadModel('Recordtype');
		$recordtypes = $this->Recordtype->find('list');
		$this->set(compact('recordtypes'));
		
		//debug ($recordtypes);
		// подключаем модель авторов
		$this->loadModel('Author');
		$this->loadModel('Teacher');
		$this->loadModel('Student');
		$this->loadModel('Extauthor');
		
		// подключаем модель связей с записями
		$this->loadModel('Authorlink');
		
		// подключаем все модели записей
		$this->loadModel('Article');
		$this->loadModel('Book'); 
		$this->loadModel('Conferencereport'); 
		$this->loadModel('Departmenteduleading'); 
		$this->loadModel('Discovery'); 
		$this->loadModel('Disserleading');
		$this->loadModel('Dissertation'); 
		$this->loadModel('Grantleading'); 
		$this->loadModel('Intellectworkresult'); 
		$this->loadModel('Journaleditmember'); 
		$this->loadModel('Lpuintroduction');
		$this->loadModel('Lpuyearmedicalloading'); 
		$this->loadModel('Medcommunityspeech'); 
		$this->loadModel('Midhighattestation'); 
		$this->loadModel('Midpedintroduction'); 
		$this->loadModel('Midwinningplace');
		$this->loadModel('Newdrug'); 
		$this->loadModel('Practicalhealthcareleading'); 
		$this->loadModel('Publication'); 
		$this->loadModel('Spcommunity'); 
		$this->loadModel('Sportcompetition');
		$this->loadModel('Sportsection'); 
		$this->loadModel('Studentworkleading'); 
		$this->loadModel('Studentworkcompetitionleading');
		$this->loadModel('Winningplace'); 
		$this->loadModel('Winningstudentworksleading'); 
		
		// массив всех записей пользователя
		$all_records = array();
		foreach ($recordtypes as $key => $value):
			$records_one_type = array ('Recordtype' => $value, 'Recordtype_id' => $key,'records' => array());
			$records = array();
			$recordlinks = $this->Authorlink->find('all', array('conditions' => array('Authorlink.author_id' => $id, 'Authorlink.recordtype_id' => $key)));
			
			/** *************************************************************************************************** **/
			// (int) 1 => '1.1 Учебно-теоретические издания',
			/** *************************************************************************************************** **/
			if ($key == 100 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Book->find('first', array('conditions' => array('Book.id' => $recordlink['Authorlink']['recordid'])));

					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}	

			/** *************************************************************************************************** **/
			//	(int) 2 => '1.2 Учебно-практические издания',
			/** *************************************************************************************************** **/
			if ($key == 200 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Book->find('first', array('conditions' => array('Book.id' => $recordlink['Authorlink']['recordid'])));
				
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}	

			/** *************************************************************************************************** **/
			//	(int) 3 => '1.3  Учебно-методические издания',
			/** *************************************************************************************************** **/
			if ($key == 300 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Book->find('first', array('conditions' => array('Book.id' => $recordlink['Authorlink']['recordid'])));
	
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}	

			/** *************************************************************************************************** **/
			//	(int) 4 => '1.4  Монографии',
			/** *************************************************************************************************** **/
			if ($key == 400 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Book->find('first', array('conditions' => array('Book.id' => $recordlink['Authorlink']['recordid'])));
		
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}		

			/** *************************************************************************************************** **/
			// (int) 5 => '1.5 Защита кандидатской диссертации',
			/** *************************************************************************************************** **/
			if ($key == 500 ) {
				foreach ($recordlinks as $recordlink):
				$record = $this->Dissertation->find('first', array('conditions' => array('Dissertation.id' => $recordlink['Authorlink']['recordid'])));
				
				$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
				$record['Authorlink'] = $recordlink['Authorlink'];
				array_push($records, $record);
				endforeach;				
			}
			
			/** *************************************************************************************************** **/
			//(int) 6 => '1.6 Защита докторской диссертации',
			/** *************************************************************************************************** **/
			if ($key == 600 ) {
				foreach ($recordlinks as $recordlink):
				$record = $this->Dissertation->find('first', array('conditions' => array('Dissertation.id' => $recordlink['Authorlink']['recordid'])));
				
				$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
				$record['Authorlink'] = $recordlink['Authorlink'];
				array_push($records, $record);
				endforeach;
			}
			
			/** *************************************************************************************************** **/
			// (int) 7 => '1.7 Руководство кандидатской диссертацией',
			/** *************************************************************************************************** **/
			if ($key == 700 ) {
				foreach ($recordlinks as $recordlink):
				$record = $this->Disserleading->find('first', array('conditions' => array('Disserleading.id' => $recordlink['Authorlink']['recordid'])));
			
				$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
				$record['Authorlink'] = $recordlink['Authorlink'];
				array_push($records, $record);
				endforeach;
			}			
			
			/** *************************************************************************************************** **/
			//(int) 8 => '1.8 Консультирование докторской диссертации',
			/** *************************************************************************************************** **/
			if ($key == 800 ) {
				foreach ($recordlinks as $recordlink):
				$record = $this->Disserleading->find('first', array('conditions' => array('Disserleading.id' => $recordlink['Authorlink']['recordid'])));
					
				$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
				$record['Authorlink'] = $recordlink['Authorlink'];
				array_push($records, $record);
				endforeach;
			}			
			
			/** *************************************************************************************************** **/
			//(int) 9 => '1.9 Выступления с докладами',
			/** *************************************************************************************************** **/
			if ($key == 900 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Conferencereport->find('first', array('conditions' => array('Conferencereport.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;		
			}		
			
			/** *************************************************************************************************** **/
			//(int) 10 => '1.10 Руководство студентами выступившими с докладами',
			/** *************************************************************************************************** **/
			if ($key == 1000 ) {
					foreach ($recordlinks as $recordlink):
						$record = $this->Conferencereport->find('first', array('conditions' => array('Conferencereport.id' => $recordlink['Authorlink']['recordid'])));
					
						$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
						$record['Authorlink'] = $recordlink['Authorlink'];
						array_push($records, $record);
					endforeach;			
			}
			/** *************************************************************************************************** **/
			//(int) 11 => '1.11 Статьи в журналах по учебно-методической и научной работе',
			/** *************************************************************************************************** **/
			if ($key == 1100 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Article->find('first', array('conditions' => array('Article.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			

			/** *************************************************************************************************** **/
			//(int) 12 => '1.12 Статьи в журналах по учебно-методической и научной работе в соавторстве с зарубежными учеными',
			/** *************************************************************************************************** **/
			if ($key == 1200 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Article->find('first', array('conditions' => array('Article.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 13 => '1.13 Статьи в журналах по научной работе с участием студентов',
			/** *************************************************************************************************** **/
			if ($key == 1300 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Article->find('first', array('conditions' => array('Article.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}

			/** *************************************************************************************************** **/
			//(int) 14 => '1.14 Публикации без студентов',
			/** *************************************************************************************************** **/
			if ($key == 1400 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Publication->find('first', array('conditions' => array('Publication.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			
			
			/** *************************************************************************************************** **/
			//(int) 15 => '1.15 Публикации с участием студентов',
			/** *************************************************************************************************** **/
			if ($key == 1500 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Publication->find('first', array('conditions' => array('Publication.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 16 => '1.18 Членство в редколлегиях изданий',
			/** *************************************************************************************************** **/
			if ($key == 1600 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Journaleditmember->find('first', array('conditions' => array('Journaleditmember.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}

			/** *************************************************************************************************** **/
			//(int) 17 => '1.19 Открытия',
			/** *************************************************************************************************** **/
			if ($key == 1700 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Discovery->find('first', array('conditions' => array('Discovery.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			
			
			/** *************************************************************************************************** **/
			//(int) 18 => '1.20 Результаты интеллектуальной деятельности без студентов',
			/** *************************************************************************************************** **/
				if ($key == 1800 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Intellectworkresult->find('first', array('conditions' => array('Intellectworkresult.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}		
			
			/** *************************************************************************************************** **/
			//(int) 19 => '1.21 Результаты интеллектуальной деятельности с участием студентов',
			/** *************************************************************************************************** **/
			if ($key == 1900 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Intellectworkresult->find('first', array('conditions' => array('Intellectworkresult.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			
			/** *************************************************************************************************** **/
			//(int) 20 => '1.22 Новые лекарственные средства',
			/** *************************************************************************************************** **/
			if ($key == 2000 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Newdrug->find('first', array('conditions' => array('Newdrug.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			
			
			/** *************************************************************************************************** **/
			//(int) 21 => '1.23 Гранты для КГМУ без студентов',
			/** *************************************************************************************************** **/
			if ($key == 2100 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Grantleading->find('first', array('conditions' => array('Grantleading.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 22 => '1.24 Руководство грантами выигранными студентами',
			/** *************************************************************************************************** **/
			if ($key == 2200 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Grantleading->find('first', array('conditions' => array('Grantleading.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			
			
			/** *************************************************************************************************** **/
			//(int) 23 => '1.25 Руководство дипломными работами',
			/** *************************************************************************************************** **/
			if ($key == 2300 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Studentworkleading->find('first', array('conditions' => array('Studentworkleading.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			
			
			/** *************************************************************************************************** **/
			//(int) 24 => '1.26 Руководство курсовыми работами',
			/** *************************************************************************************************** **/
			if ($key == 2400 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Studentworkleading->find('first', array('conditions' => array('Studentworkleading.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
			
			/** *************************************************************************************************** **/
			//(int) 25 => '1.27 Руковдство студентами принявшими участие в конкурсах',
			/** *************************************************************************************************** **/
			if ($key == 2500 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Studentworkcompetitionleading->find('first', array('conditions' => array('Studentworkcompetitionleading.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			
			
			/** *************************************************************************************************** **/
			//(int) 26 => '1.28 Поощрения студенческих работ',
			/** *************************************************************************************************** **/
			if ($key == 2600 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Winningstudentworksleading->find('first', array('conditions' => array('Winningstudentworksleading.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			
			/** *************************************************************************************************** **/
			//(int) 27 => '1.29 Руководство работой воспитательных структур',
			/** *************************************************************************************************** **/
			if ($key == 2700 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Departmenteduleading->find('first', array('conditions' => array('Departmenteduleading.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 28 => '1.30 Призовые места по итогам конкурсов',
			/** *************************************************************************************************** **/
			if ($key == 2800 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Winningplace->find('first', array('conditions' => array('Winningplace.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 29 => '1.31.1 Участие в физкультурно-массовой и спортивной работе: систематические занятия  в секциях',
			/** *************************************************************************************************** **/
			if ($key == 2900 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Sportsection->find('first', array('conditions' => array('Sportsection.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 30 => '1.31.2 Участие в физкультурно-массовой и спортивной работе: участие в спартакиаде Бодрость и здоровье',
			/** *************************************************************************************************** **/
			if ($key == 3000 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Sportcompetition->find('first', array('conditions' => array('Sportcompetition.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}	
					
			/** *************************************************************************************************** **/
			//(int) 31 => '2.1 Внедрение инновацинных педагогических технологий обучения и воспитания',
			/** *************************************************************************************************** **/
			if ($key == 3100 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Midpedintroduction->find('first', array('conditions' => array('Midpedintroduction.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 32 => '2.2 Призовые места по итогам конкурсов и смотров',
			/** *************************************************************************************************** **/
			if ($key == 3200 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Midwinningplace->find('first', array('conditions' => array('Midwinningplace.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 33 => '2.3 Аттестация преподавателей колледжа на высшую квалификационную категорию',
			/** *************************************************************************************************** **/
			if ($key == 3300 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Midhighattestation->find('first', array('conditions' => array('Midhighattestation.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 34 => '3.1 Руководство работой региональных отделений научно-практических обществ',
			/** *************************************************************************************************** **/
			if ($key == 3400 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Spcommunity->find('first', array('conditions' => array('Spcommunity.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 35 => '3.2 Выступления с докладами на заседаниях научных сообществ',
			/** *************************************************************************************************** **/
			if ($key == 3500 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Medcommunityspeech->find('first', array('conditions' => array('Medcommunityspeech.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 36 => '3.3 Руководство в практическом здравоохранении',
			/** *************************************************************************************************** **/
			if ($key == 3600 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Practicalhealthcareleading->find('first', array('conditions' => array('Practicalhealthcareleading.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}
						
			/** *************************************************************************************************** **/
			//(int) 37 => '3.4 Выполнение леченой нагрузки за год',
			/** *************************************************************************************************** **/
			if ($key == 3700 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Lpuyearmedicalloading->find('first', array('conditions' => array('Lpuyearmedicalloading.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			
			
			/** *************************************************************************************************** **/			
			//(int) 38 => '3.5 Внедрение в работу ЛПУ новых методов лечения, диагностики и др'
			/** *************************************************************************************************** **/
			if ($key == 3800 ) {
				foreach ($recordlinks as $recordlink):
					$record = $this->Lpuintroduction->find('first', array('conditions' => array('Lpuintroduction.id' => $recordlink['Authorlink']['recordid'])));
						
					$record['authors'] = $this->getauthors($key, $recordlink['Authorlink']['recordid']);
					$record['Authorlink'] = $recordlink['Authorlink'];
					array_push($records, $record);
				endforeach;
			}			

			
			// собираем массив записей одного типа			
			$records_one_type['records'] = $records; 
			
			// запоминаем все записи одного типа
			array_push($all_records, $records_one_type);
			//debug($recordlinks);
		endforeach;
		//debug ($all_records);
		$this->set('all_records', $all_records);
	
	}
	
	/** ************************************************************************************************************
	 * 
	 * addrecord перенаправляет к контроллеру записей соответствующего типа 
	 * 
	 * ************************************************************************************************************/
	
	public function addrecord() {
		//читаем тип записи чтобы сохранить его в Authorlink потом
		$recordtype_id = $this->data['Record']['recordtype_id'];
		
		if (empty($recordtype_id)) {
			$this->Session->setFlash(__('Выберите тип записи для добавления!'));
			return $this->redirect(array('action' => 'index'));
		}
		
		switch ($recordtype_id) {
			case 50: return $this->redirect(array('controller' => 'teachers', 'action' => 'edit')); break;
			case 51: return $this->redirect(array('controller' => 'teachers', 'action' => 'edit')); break;
			case 100: return $this->redirect(array('controller' => 'books', 'action' => 'add', $recordtype_id)); break;
			case 200: return $this->redirect(array('controller' => 'books', 'action' => 'add', $recordtype_id)); break;
			case 300: return $this->redirect(array('controller' => 'books', 'action' => 'add', $recordtype_id)); break;
			case 400: return $this->redirect(array('controller' => 'books', 'action' => 'add', $recordtype_id)); break;
			case 500: return $this->redirect(array('controller' => 'dissertations', 'action' => 'add', $recordtype_id)); break;
			case 600: return $this->redirect(array('controller' => 'dissertations', 'action' => 'add', $recordtype_id)); break;
			case 700: return $this->redirect(array('controller' => 'disserleadings', 'action' => 'add', $recordtype_id)); break;
			case 800: return $this->redirect(array('controller' => 'disserleadings', 'action' => 'add', $recordtype_id)); break;
			case 900: return $this->redirect(array('controller' => 'conferencereports', 'action' => 'add', $recordtype_id)); break;
			case 1000: return $this->redirect(array('controller' => 'conferencereports', 'action' => 'add', $recordtype_id)); break;
			case 1100: return $this->redirect(array('controller' => 'articles', 'action' => 'add', $recordtype_id)); break;
			case 1200: return $this->redirect(array('controller' => 'articles', 'action' => 'add', $recordtype_id)); break;
			case 1300: return $this->redirect(array('controller' => 'articles', 'action' => 'add', $recordtype_id)); break;
			case 1400: return $this->redirect(array('controller' => 'publications', 'action' => 'add', $recordtype_id)); break;
			case 1500: return $this->redirect(array('controller' => 'publications', 'action' => 'add', $recordtype_id)); break;
			case 1550: return $this->redirect(array('controller' => 'teachers', 'action' => 'edit')); break;
			case 1551: return $this->redirect(array('controller' => 'teachers', 'action' => 'edit')); break;
			case 1600: return $this->redirect(array('controller' => 'journaleditmembers', 'action' => 'add', $recordtype_id)); break;
			case 1700: return $this->redirect(array('controller' => 'discoveries', 'action' => 'add', $recordtype_id)); break;
			case 1800: return $this->redirect(array('controller' => 'intellectworkresults', 'action' => 'add', $recordtype_id)); break;
			case 1900: return $this->redirect(array('controller' => 'intellectworkresults', 'action' => 'add', $recordtype_id)); break;
			case 2000: return $this->redirect(array('controller' => 'newdrugs', 'action' => 'add', $recordtype_id)); break;
			case 2100: return $this->redirect(array('controller' => 'grantleadings', 'action' => 'add', $recordtype_id)); break;
			case 2200: return $this->redirect(array('controller' => 'grantleadings', 'action' => 'add', $recordtype_id)); break;
			case 2300: return $this->redirect(array('controller' => 'studentworkleadings', 'action' => 'add', $recordtype_id)); break;
			case 2400: return $this->redirect(array('controller' => 'studentworkleadings', 'action' => 'add', $recordtype_id)); break;
			case 2500: return $this->redirect(array('controller' => 'studentworkcompetitionleadings', 'action' => 'add', $recordtype_id)); break;
			case 2600: return $this->redirect(array('controller' => 'winningstudentworksleadings', 'action' => 'add', $recordtype_id)); break;
			case 2700: return $this->redirect(array('controller' => 'departmenteduleadings', 'action' => 'add', $recordtype_id)); break;
			case 2800: return $this->redirect(array('controller' => 'winningplaces', 'action' => 'add', $recordtype_id)); break;
			case 2900: return $this->redirect(array('controller' => 'sportsections', 'action' => 'add', $recordtype_id)); break;
			case 3000: return $this->redirect(array('controller' => 'sportcompetitions', 'action' => 'add', $recordtype_id)); break;
			case 3100: return $this->redirect(array('controller' => 'midpedintroductions', 'action' => 'add', $recordtype_id)); break;
			case 3200: return $this->redirect(array('controller' => 'midwinningplaces', 'action' => 'add', $recordtype_id)); break;
			case 3300: return $this->redirect(array('controller' => 'midhighattestations', 'action' => 'add', $recordtype_id)); break;
			case 3400: return $this->redirect(array('controller' => 'spcommunities', 'action' => 'add', $recordtype_id)); break;
			case 3500: return $this->redirect(array('controller' => 'medcommunityspeeches', 'action' => 'add', $recordtype_id)); break;
			case 3600: return $this->redirect(array('controller' => 'practicalhealthcareleadings', 'action' => 'add', $recordtype_id)); break;
			case 3700: return $this->redirect(array('controller' => 'lpuyearmedicalloadings', 'action' => 'add', $recordtype_id)); break;
			case 3800: return $this->redirect(array('controller' => 'lpuintroductions', 'action' => 'add', $recordtype_id)); break;

			
		}
	} 
	
	/** *********************************************************************************************************************** 
	 * 
	 * 	// Поиск авторов по конкретной записи
	 * 
	 * ***********************************************************************************************************************/

	private function getauthors ($recordtype_id = null, $record_id = null) {
		$this->loadModel('Authorlink');
		// $recordtype_id это $key 
		// $record_id это $recordlink['Authorlink']['recordid']
		
		$authors_ids = $this->Authorlink->find('all', array('conditions' =>array('Authorlink.recordtype_id' => $recordtype_id, 'Authorlink.recordid' => $record_id), 'recursive' => -1));
		$ids = array();
		
		//debug ($authors_ids);
		
		foreach ($authors_ids as $author_id):
		array_push($ids, $author_id['Authorlink']['author_id']);
		endforeach;
		
		$tmp_authors = $this->Author->find('all', array('conditions' => array('Author.id' =>$ids), 'recursive' => -1));
		//debug ($tmp_authors);
		// массив всех авторов записи
		$authors = array();
		foreach ($tmp_authors as $tmp_author):
			$fio = '';
			if ($tmp_author['Author']['authortype_id'] == 1){
				$author = $this->Teacher->find('first', array('conditions' => array('Teacher.id' => $tmp_author['Author']['authorid']), 'recursive' => -1));
				$fio = $author['Teacher']['lastname'].' ';
				if (!empty($author['Teacher']['firstname'])) {
					$fio .= mb_substr($author['Teacher']['firstname'], 0,1);
				}
				if (!empty($author['Teacher']['surname'])) {
					$fio .= mb_substr($author['Teacher']['surname'], 0,1);
				}
			}
			if ($tmp_author['Author']['authortype_id'] == 2){
				$author = $this->Student->find('first', array('conditions' => array('Student.id' => $tmp_author['Author']['authorid']), 'recursive' => -1));
				$fio = $author['Student']['lastname'].' ';
				if (!empty($author['Student']['firstname'])) {
					$fio .= mb_substr($author['Student']['firstname'], 0,1);
				}
				if (!empty($author['Student']['surname'])) {
					$fio .= mb_substr($author['Student']['surname'], 0,1);
				}
			}
			if ($tmp_author['Author']['authortype_id'] == 3){
				$author = $this->Extauthor->find('first', array('conditions' => array('Extauthor.id' => $tmp_author['Author']['authorid']), 'recursive' => -1));
				$fio = $author['Extauthor']['lastname'].' ';
				if (!empty($author['Extauthor']['firstname'])) {
					$fio .= mb_substr($author['Extauthor']['firstname'], 0,1);
				}
				if (!empty($author['Extauthor']['surname'])) {
					$fio .= mb_substr($author['Extauthor']['surname'], 0,1);
				}
			}
			array_push($authors, $fio);
		endforeach;
		// возвращаем всех авторов связанных с конкретной записью
		return $authors;
	}
}
?>